﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Forms.VisualStyles;
using HighDiveAdmin.Engine;
using HighDiveAdmin.Resources;

//Html class 

namespace HTML_FORM
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StreamWriter sWriter = new StreamWriter("htmlFile.html");

            // calling variables from other classes 
            Dive d1;
            Dive d2;
            Dive d3;
            Dive d4;
            Dive d5;
            Dive d6;
            Dive d7;
            Dive d8;

            Diver p1;
            Diver p2;
            Diver p3;
            Diver p4;

            DiveList dlist;

            p1 = new Diver("NEJ", "Max", "Sevon", Gender.Male, 3);
            p2 = new Diver("NEJ", "Victor", "Hedlund", Gender.Male, 4);
            p3 = new Diver("NEJ", "Anders", "Alfredsson", Gender.Male, 1);
            p4 = new Diver("NEJ", "Arsema", "Asefaw", Gender.Female, 2);
            

            d1 = new Dive(p1, "404B", 1, 5) { TotalScore = 10, QueueOrderNumber = 1 };
            d2 = new Dive(p1, "404B", 2, 5) { TotalScore = 35, QueueOrderNumber = 4 };
            d3 = new Dive(p2, "404B", 1, 5) { TotalScore = 15, QueueOrderNumber = 2 };
            d4 = new Dive(p2, "404B", 2, 5) { TotalScore = 5, QueueOrderNumber = 8 };
            d5 = new Dive(p3, "404B", 1, 5) { TotalScore = 47, QueueOrderNumber = 3 };
            d6 = new Dive(p3, "404B", 2, 5) { TotalScore = 13, QueueOrderNumber = 6 };
            d7 = new Dive(p4, "404B", 1, 5) { TotalScore = 13, QueueOrderNumber = 5 };
            d8 = new Dive(p4, "404B", 2, 5) { TotalScore = 9, QueueOrderNumber = 7 };

            dlist = new DiveList { d1, d2, d3, d4, d5, d6, d7, d8 };

            //html codes for a website

            sWriter.WriteLine("<html>");

            sWriter.WriteLine("<head>");
            sWriter.WriteLine("</head>");

            sWriter.WriteLine("<body style=background-color:#352912>");
           
            //creating a table at the center of the web page
            sWriter.WriteLine("<table WIDTH=75% HEIGHT=70% border=70 style=border-color:#FFD175 border-style:groove align=center>");
           
            // columns 
            sWriter.WriteLine("<TR>");
            sWriter.WriteLine("<TD colspan=5 style=background-color:#211500><center><BR><BR><marquee><FONT COLOR=white align=center SIZE=8 FACE=MONOTYPE CORSIVA> History Of Recent Divers </marquee></font></td>");
            sWriter.WriteLine("</TR>");

            sWriter.WriteLine("<tr>");

            sWriter.WriteLine("<td width=10% style=background-color:#FFD175>");
            sWriter.WriteLine("Start Number");
            sWriter.WriteLine("</td>");


            sWriter.WriteLine("<td width=22% style=background-color:#FFD175>");
            sWriter.WriteLine("First name");
            sWriter.WriteLine("</td>");

            sWriter.WriteLine("<td width=17% style=background-color:#FFD175>");
            sWriter.WriteLine("Last name");
            sWriter.WriteLine("</td>");

            sWriter.WriteLine("<td  width=13% style=background-color:#FFD175>");
            sWriter.WriteLine(" Gender ");
            sWriter.WriteLine("</td>");

            sWriter.WriteLine("<td width=13% style=background-color:#FFD175>");
            sWriter.WriteLine("Total score");
            sWriter.WriteLine("</td>");
            sWriter.WriteLine("</tr>");


            //printing out the name, gender and totalScore of each divers using a loop
            //Sorting the loop by diver name
            Dive prev = null;
            dlist.Sort(new DiveListComparer(DiveListSortType.DiverName));
            foreach (var VARIABLE in dlist)
            {
       
                if ( (prev != null) &&
                    (prev.Diver.FirstName == VARIABLE.Diver.FirstName) &&
                    (prev.Diver.LastName == VARIABLE.Diver.LastName))
                {
                    if (prev.Diver.PersonDbId == VARIABLE.Diver.PersonDbId)
                    {
                        sWriter.WriteLine("<tr style=background-color:#352912>");
                        sWriter.WriteLine("<td><FONT COLOR=white>");
                        sWriter.WriteLine(VARIABLE.Diver.StartNumber);
                        sWriter.WriteLine("</font></td>");
                        sWriter.WriteLine("<td><FONT COLOR=white>");
                        sWriter.WriteLine(VARIABLE.Diver.FirstName);
                        sWriter.WriteLine("</font></td>");
                        sWriter.WriteLine("<td><FONT COLOR=white>");
                        sWriter.WriteLine(VARIABLE.Diver.LastName);
                        sWriter.WriteLine("</font></td>");
                        sWriter.WriteLine("<td><FONT COLOR=white>");
                        sWriter.WriteLine(VARIABLE.Diver.Gender);
                        sWriter.WriteLine("</font></td>");
                        sWriter.WriteLine("<td><FONT COLOR=white>");

                        sWriter.Write(prev.TotalScore + VARIABLE.TotalScore);
                        sWriter.WriteLine("</font></td>");
                        sWriter.WriteLine("</tr>");
                    }
                }
                
                prev = VARIABLE;
            }

            //creating new table for divers jugdeScore 
            sWriter.WriteLine("<tr>");
            sWriter.WriteLine("<td width=22%>");
            sWriter.WriteLine("<table WIDTH=100% HEIGHT=70% border= 3 style=border-color:#FFD175 border-style:groove align=center>");
            sWriter.WriteLine("<th style=background-color:#FFD175>");
            sWriter.WriteLine("  Divers Jugde Score  ");
            sWriter.WriteLine("</th>");
            sWriter.WriteLine("</td>");
            sWriter.WriteLine("</tr>");
            sWriter.WriteLine("</table>");

            //printing out the name, gender and totalScore of each divers judgeScore using a loop
            //Sorting the loop by diver name
            dlist.Sort(new DiveListComparer(DiveListSortType.DiverName));
            int i =0;
            foreach (var dive in dlist)
            {
                sWriter.WriteLine("<tr style=background-color:#352912>");
                sWriter.WriteLine("<td><FONT COLOR=white>");
                sWriter.WriteLine(++i);
                sWriter.WriteLine(".");
                sWriter.WriteLine(dive.Diver.FirstName);
                sWriter.WriteLine("Dive Score ");
                sWriter.WriteLine(dive.DiveNumber);
                sWriter.WriteLine("</font></td>");
                sWriter.WriteLine("<td><FONT COLOR=white><center>");
                sWriter.WriteLine(dive.TotalScore);
                sWriter.WriteLine("</font></td>");
                sWriter.WriteLine("</tr>");
            }

            //closing the main table
            sWriter.WriteLine("</table>");
            sWriter.WriteLine("</body>");
            sWriter.WriteLine("</html>");
            sWriter.Close();
        }

        
    }

}
